import instance from '../../utils/axios'
//1.获取所有频道列表
function getChannelList(){
    return instance({
        url:'/v1_0/channels',
        method:'get',
    })
}
export {getChannelList}
//获取文章接口
function getArticleList({channel_id,timestamp}){
    return instance({
        url:'/v1_0/articles',
        method:'get',
        params:{
            with_top:1,
            channel_id,
            timestamp
        }
    })
}
export {getArticleList}
//获取新闻文章详情
function getArticleInfo({id}){
    return instance({
        url:'/v1_0/articles/'+id,
        method:'get',
    })
}
//关注用户
export {getArticleInfo}
function followUser({target}){
    return instance({
        url:'/v1_0/user/followings',
        method:'post',
        data:{target}
    })
}
export {followUser}
//取消关注
function unFollowUser({target}){
    return instance({
        url:'/v1_0/user/followings/'+target,
        method:'delete',
    })
}
export {unFollowUser}

/* 6.点赞与取消点赞 */

//点赞
const addPraise = id => {
    return instance({
      method: 'post',
      url: '/v1_0/article/likings',
      data: {
        target: id
      }
    })
  }
  
  //取消点赞
  const cancelPraise = id => {
    return instance({
      method: 'delete',
      //这个接口的id直接在路径后面拼接  格式： url/target
      url: '/v1_0/article/likings/' + id
    }
    )
  }
  
  //导出接口
  export { addPraise, cancelPraise }
  //不喜欢
  function addDisLike(id){
      return instance({
          url:'/v1_0/article/dislikes',
          method:'post',
          data:{
              target:id
          }
      })
  }
  //取消不喜欢
  function cancelDisLike(id){
      return instance({
          url:'/v1_0/article/dislikes/'+id,
          method:'delete'
      })
  }
  export {addDisLike,cancelDisLike}
  //推荐词接口
  function getSuggestion(q){
      return instance({
          url:'/v1_0/suggestion',
          method:'get',
          params:{
              q
          }
      })
  }
export {getSuggestion}
//搜索结果
function getSearchList({page,per_page,q}){
    return instance({
        url:'v1_0/search',
        method:'get',
        params:{
            page,
            per_page,
            q
        }
    })
}
export {getSearchList}